import React from 'react'
import { Provider } from 'react-redux'
import { BrowserRouter as Router } from 'react-router-dom'
import { ConfigProvider } from 'antd'
import zhCN from 'antd/es/locale/zh_CN'
import Routes from './routers' // 路由
import store from './store'

import './app.less'

const App = () => {
  return (
    <React.StrictMode>
      <ConfigProvider locale={zhCN}>
        <Provider store={store}>
          <Router>
            <Routes />
          </Router>
        </Provider>
      </ConfigProvider>
    </React.StrictMode>
  )
}

// 解决：ios12 键盘下落 页面不下落
const { userAgent } = navigator
const u = userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
if (u) {
  document.body.addEventListener('focusout', () => {
    setTimeout(() => {
      const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
      window.scrollTo({
        top: Math.max(scrollHeight - 1, 0),
        behavior: 'smooth',
      })
    }, 100)
  })
}

export default App
